package com.metaera.app.ui.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.metaera.app.R;
import com.metaera.app.data.model.HomeTopNewsResponse;
import com.metaera.app.ui.activities.ArticleDetailsActivity;
import com.metaera.app.utils.image.GlideApp;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class HomeBannerAdapter extends BannerAdapter<HomeTopNewsResponse.BnnerLists, HomeBannerAdapter.BannerViewHolder> {

    public HomeBannerAdapter(List<HomeTopNewsResponse.BnnerLists> data) {
        super(data);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        return new BannerViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_home_banner, parent, false));
    }

    @Override
    public void onBindView(BannerViewHolder holder, HomeTopNewsResponse.BnnerLists item, int position, int size) {

        GlideApp.with(holder.itemView)
                .load(item.getPic())
                .normal()
                .into(holder.imageView);

        holder.itemView.setOnClickListener(v ->{
            Context context = v.getContext();
            context.startActivity(ArticleDetailsActivity.newInstance(context, item.getId()));
        });
    }

    static class BannerViewHolder extends RecyclerView.ViewHolder {

        ImageView imageView;

        public BannerViewHolder(@NonNull View view) {
            super(view);
            imageView = view.findViewById(R.id.banner_image_view);
        }
    }

}
